package net.funwoo.pandago.util;

import android.content.Context;

import com.afollestad.materialdialogs.MaterialDialog;
import com.makeramen.roundedimageview.RoundedTransformationBuilder;
import com.squareup.picasso.Transformation;

import net.funwoo.pandago.AppHelper;

/**
 * Created by Bob Peng on 2015/5/6.
 */
public class UiUtils {

    private static float sDensity = 0;

    public static MaterialDialog getMsgDialog(Context context, String title, String text) {
        return new MaterialDialog.Builder(context)
                .title(title)
                .content(text)
                .positiveText(android.R.string.ok)
                .negativeText(android.R.string.cancel)
                .build();
    }

    public static MaterialDialog getLoadingDialog(Context context, String msg) {
        return new MaterialDialog.Builder(context)
                .content(msg)
                .progress(true, 0)
                .build();
    }

    public static Transformation getRoundedTransformation() {
        return new RoundedTransformationBuilder()
                .borderWidthDp(0)
                .oval(true)
                .build();
    }

    public static int dp2px(int dp) {

        return (int) (dp * getDensity() + 0.5f);
    }

    public static float getDensity() {
        if (sDensity == 0) {
            try {
                sDensity = AppHelper.getAppApplication().getResources().getDisplayMetrics().density;
            } catch (Exception e) {
                sDensity = 2f;
            }

        }
        return sDensity;
    }
}
